package home

type Bitmap struct {
	Bitmap_size int
	Bitmap_data []byte
}

func (b *Bitmap) Init(size int) {
	b.Bitmap_size = size
	b.Bitmap_data = make([]byte, size/8+1)
}

func (b *Bitmap) Set(bit int) {
	b.Bitmap_data[bit/8] |= 1 << (bit % 8)
}

func (b *Bitmap) Test(bit int) bool {
	return b.Bitmap_data[bit/8]&(1<<(bit%8)) != 0
}

func (b *Bitmap) Clear(bit int) {
	b.Bitmap_data[bit/8] &= ^(1 << (bit % 8))
}

func (b *Bitmap) ClearAll() {
	for i := range b.Bitmap_data {
		b.Bitmap_data[i] = 0
	}
}

func (tar *Bitmap) Paste(src *Bitmap) {
	for i := 0; i < len(tar.Bitmap_data); i++ {
		tar.Bitmap_data[i] |= src.Bitmap_data[i]
	}
}
